package d1208.Ljs2.Ljs8;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class Demo1 {
    public static void main(String[] args)throws Exception {
        ArrayList<Cat>cats=new ArrayList<>();
        Class<?> aClass = Class.forName("Ljs2.Ljs8.Cat");
        Constructor<?> constructor = aClass.getConstructor();
        Object o = constructor.newInstance();
        Method setName = aClass.getMethod("setName", String.class);
        setName.setAccessible(true);
        List<String>list=FileUtils.readLines(new File("E:\\代码\\代码练习和作业\\Zuoye12月6号\\src\\Ljs2\\Ljs8\\Catdata.txt"));
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i).replace("'", "");
            String s1 = s.replace(" ", "=");
            String[] arr = s1.split("=");
            for (int j = 0; j < arr.length; j++) {
                if (arr[j].equals("name")){
                    setName.invoke(o, arr[j + 1]);
                   System.out.println(aClass.getMethod("getName").invoke(o));
                }
            }
        }
    }
}
